import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;

public class Main {


    static int day = 0;


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Person p = new Person(Gender.男, "ysm", 19, "201621123069");
        Library library = new Library();
        try {
            FileReader file = new FileReader("library.txt");
            BufferedReader bufferedReader = new BufferedReader(file);
            String s = null;
            while ((s = bufferedReader.readLine()) != null) {
                String[] ss = s.split(" ");
                book b = new book(ss[0], ss[1], false);
                library.add(b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        while (true) {
            Manu();
            int i = in.nextInt();
            if (i < 0 || i > 7) {
                Err();
                continue;
            }
            switch (i) {
                case 1:
                    p.ShowMessage();
                    break;
                case 2:
                    library.Show();
                    break;
                case 3:
                    library.Lend(p);
                    break;
                case 4:
                    p.ShowLend();
                    break;
                case 5:
                    library.Repay(p);
                    break;
                case 6:
                    day++;
                    PastTime(p.getList());
                    break;
                case 7:
                    System.exit(0);
            }
        }
    }

    static void Manu() {
        System.out.println("1.查看个人信息");
        System.out.println("2.浏览图书");
        System.out.println("3.借图书");
        System.out.println("4.查看已借图书");
        System.out.println("5.还书");
        System.out.println("6.时光流逝");
        System.out.println("7.退出系统");
        System.out.println("当前时间: " + day + "天");
        System.out.println("请输入:");

    }

    static void Err() {
        System.out.println("输入错误请重新输入！");
    }

    static void PastTime(List<book> list) {
        for (book b :
                list) {
            b.setLendTime(b.getLendTime() - 1 < 0 ? 0 : b.getLendTime() - 1);
            if (b.getLendTime() == 0) {
                System.out.println(b.getName() + "已逾期");
            }
        }
    }
}
